<template>
  <div id="body">
    <div id="login">
      <div class="title">小U商城后台管理系统</div>
      <!-- model : 表单的数据 -->
      <!-- rules : 校验的规则 -->
      <!-- ref : 获取这个DOM节点，方便操作 -->
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="80px"
        class="demo-ruleForm"
      >
        <el-form-item prop="name" label="用户名">
          <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item prop="password" label="密码">
          <el-input v-model="ruleForm.password"></el-input>
        </el-form-item>
        <el-button id="btn" type="primary" @click="submitForm('ruleForm')"
          >立即登录</el-button
        >
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        name: "",
        password: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "change" },
        ],
      },
    };
  },
  
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style scoped>
#login {
  width: 500px;
  margin: 150px auto;
  background-color: #fff;
  padding: 30px 60px 60px 30px;
  border-radius: 8px;
}
.title {
  color: orange;
  text-align: center;
  font-weight: bolder;
  margin: 10px;
}
#btn {
  width: 420px;
  display: block;
  margin-left: 80px;
}
#body {
  background: url(../../assets/cts-loginbg.jpeg);
  height: 100vh;
  overflow: hidden;
}
</style>